package com.yckj.web.uol.service.Impl;


import com.yckj.web.uol.dao.UserMapper;
import com.yckj.web.uol.entity.Labmember;
import com.yckj.web.uol.entity.User;
import com.yckj.web.uol.service.IUserService;
import com.yckj.web.uol.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @Classname UserServiceImpl
 * @Description TODO
 * @Copyright:Copyright(c) 2021
 * @Company 英才汇硕信息科技有限公司
 * @Author xu
 * @Version 1.0
 * @Date 2021/7/20 11:15
 */
public class UserServiceImpl implements IUserService {
    @Override
    public User login(User user) {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user1 = mapper.selectByUsernameAndPwd(user.getUsername(), user.getPasswords());
        if(user1 != null){
            return user1;
        }
        MyBatisUtil.close(session);
        return null;
    }

    @Override
    public boolean register(User user) {
        boolean flag = false;
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        int insert = mapper.insert(user);
        if (insert>0){
            session.commit();
            flag=true;
            System.out.println("注册成功");
            return  flag;
        }else {
            session.rollback();
            System.out.println("注册失败");
        }
    return flag;
    }

}
